<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "supplier".
 *
 * @property integer $id
 * @property string $company
 * @property string $phone
 * @property string $name
 * @property string $address
 * @property string $mail
 * @property string $desc
 * @property integer $status
 * @property integer $user_id
 * @property string $created_at
 * @property string $updated_at
 */
class Supplier extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'supplier';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['company'], 'required'],
            [['status', 'user_id'], 'integer'],
            [['created_at', 'updated_at'], 'safe'],
            [['company', 'address', 'mail'], 'string', 'max' => 255],
            [['mail'], 'email'],
            [['phone', 'bank_account', 'bank_name', 'bank_account_name', 'bank_address'], 'string', 'max' => 64],
            [['name'], 'string', 'max' => 32],
            [['desc'], 'string', 'max' => 1024],
        ];
    }

    // 保存前处理
    public function beforeSave($insert) {//{{{
        if($insert){
            $this->created_at = date("Y-m-d H:i:s");
            $this->user_id    = Yii::$app->user->id;
        }
        return parent::beforeSave($insert);
    }//}}}

       
    // 保存后处理
    public function afterSave($insert, $changedAttributes){//{{{
    
    }//}}} 


    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app.supplier', 'ID'),
            'company' => Yii::t('app.supplier', 'Company'),
            'phone' => Yii::t('app.supplier', 'Phone'),
            'name' => Yii::t('app.supplier', 'Name'),
            'address' => Yii::t('app.supplier', 'Address'),
            'mail' => Yii::t('app.supplier', 'Mail'),
            'desc' => Yii::t('app', 'Desc'),
            'status' => Yii::t('app', 'Status'),
            'user_id' => Yii::t('app', 'User ID'),
            'created_at' => Yii::t('app', 'Created At'),
            'updated_at' => Yii::t('app', 'Updated At'),
            'bank_account' => Yii::t('app', 'Bank Account'),
            'bank_name' => Yii::t('app', 'Bank Name'),
            'bank_account_name' => Yii::t('app', 'Bank Account Name'),
            'bank_address' => Yii::t('app', 'Bank Address'),
        ];
    }
}
